package com.guchenbo.example.security;

import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.util.Enumeration;

/**
 * @Author gucb
 * @Date 2017/9/6.
 */
public class MainTest {

    public static void main(String[] args) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("jks");
        //        System.out.println(System.getenv("JAVA_HOME"));
        String key = System.getProperty("java.home") + "/lib/security/cacerts";
        String pass = "changeit";
        //        System.out.println(System.getProperty("java.home"));
        keyStore.load(new FileInputStream(new File(key)), pass.toCharArray());

        System.out.println(keyStore.getProvider().getClass());

        Enumeration<String> e = keyStore.aliases();
        while (e.hasMoreElements()) {
            Certificate cer = keyStore.getCertificate(e.nextElement());

            System.out.println(cer);
            System.out.println(cer.getEncoded());
            System.out.println(cer.getType());
            System.out.println(cer.getPublicKey());

            break;
        }
    }
}
